#ifndef _TTHREADPOOL_H_
#define _TTHREADPOOL_H_
#include <deque>
#include <mutex>
#include <vector>
#include <thread>
#include <algorithm>
#include <functional>
#include <condition_variable>
typedef std::function<void()> TTask;
#include "TNoCopyable.h"
class TThreadPool : TNoCopyable
{
public:
    TThreadPool();
    virtual ~TThreadPool();

    void Start(int numThreads);
    void Stop();
    void Run(const TTask& tk);
    void Run(TTask&& tk);
    TTask Take();
private:
    bool running_;
    std::mutex mutex_;
    std::deque<TTask> queue_;
    std::condition_variable notempty_;
    std::vector<std::thread> threads_;

    void runInThread();
};


#endif